package com.web.music.portal.mvc;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.web.music.model.Singer;

public class SingerFormValidator implements Validator {

	public boolean supports(Class givenClass) {
		return givenClass.equals(Singer.class);
	}

	public void validate(Object obj, Errors errors) {
		Singer singer = (Singer) obj;
		if (singer == null) {
			errors.reject("error.nullpointer", "Null data received");
		} else {
			if ("".equals(singer.getName())) {
				errors.rejectValue("name", "error.empty", "Name is required!");
			}
		}
	}

}
